const mysql = require("mysql");

const db = mysql.createConnection({
  host: "127.0.0.1",
  user: "root",
  password: "root",
  database: "electronic", // 公司的
  // database: "commerce", // 家里的
});
db.connect((err) => {
  if (err) {
    console.log(err);
  } else {
    console.log("connect success");
  }
});
/**
 * statement : sql语句
 * cb 回调
 * */

const connection = (statement, parame, cb) => {
  db.query(statement, [...parame], (err, results) => {
    if (err) {
      console.log(err);
      new Error("database connection fail");
    } else {
      cb(results);
    }
  });
};
module.exports = connection;
